package com.rzico.sbl.ui.report.manager

import com.rzico.sbl.R
import com.rzico.sbl.databinding.ActivityReportIncomeListBinding
import com.rzico.sbl.model.CommonData
import com.rzico.sbl.viewmodel.ReportDriverViewModel
import com.xinnuo.common.extend.get
import com.xinnuo.common.extend.startActivityEx
import com.xinnuo.common.listener.onTabSelectedListener
import com.xinnuo.common.decoration.SpaceTBDecoration
import com.xinnuo.common_ui.base.BaseActivity
import com.xinnuo.common_ui.base.loadLinear
import com.xinnuo.slimadapter.SlimAdapter

class ReportIncomeListActivity : BaseActivity(R.layout.activity_report_income_list) {

    private val mBinding by lazy { ActivityReportIncomeListBinding.bind(getRootView()) }

    override fun getViewModel() = get<ReportDriverViewModel>()

    override fun initData() {
        setToolbarVisibility(false)
        initTabLayout()
        initLayout()

        repeat(20) {
            mList.add(CommonData(it.toString()))
        }

        mAdapter.setDataList(mList)
    }

    private fun initLayout() {
        mBinding.listLayout.apply {
            emptyLayout.also {
                it.emptyHint.text = "暂无相关收入信息！"
            }

            recycleList.also { view ->
                view.loadLinear(
                    refresh = swipeRefresh,
                    onRefresh = { },
                    onLoad = { }
                )

                view.addItemDecoration(SpaceTBDecoration(hasHeader = false))

                mAdapter = SlimAdapter.creator()
                    .register<CommonData>(R.layout.item_report_goods_list) { jector, _, _ ->
                        jector.apply {
                            clicked { startActivityEx<ReportStationDetailActivity>() }
                        }
                    }
                    .attachTo(view)
            }
        }
    }

    private fun initTabLayout() {
        mBinding.incomeTab.apply {
            onTabSelectedListener {
                onTabSelected {}
            }

            addTab(this.newTab().setText("商品收入"), true)
            addTab(this.newTab().setText("押桶"), false)
            addTab(this.newTab().setText("买桶"), false)
            addTab(this.newTab().setText("补差价"), false)
        }
    }

}